package com.aaa.project.controller;


import com.aaa.entity.OOrder;
import com.aaa.project.service.IOOrderService;
import com.aaa.project.util.GetBid;
import com.aaa.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单信息 前端控制器
 * </p>
 *
 * @author zhangxuhui
 * @since 2023-02-03
 */
@RestController
@RequestMapping("/o-order")
public class OOrderController {

    @Resource
    private IOOrderService orderService;

    @Resource
    private GetBid getBid;


    @GetMapping("findAll")
    public Result findAll(Integer curr, Integer pageSize, Principal principal, Integer zhuangtai) {
        return new Result<>(orderService.findAll(principal, curr, pageSize, zhuangtai));
    }


    @GetMapping("cancle/{id}")
    public Result cancle(@PathVariable String id) {
        return   new Result<>(orderService.cancle(id));
    }

    @GetMapping("delete/{code}")
    public Result delete(@PathVariable String code){
        return   new Result<>(orderService.delete(code));
    }

    @PostMapping("updateTime")
    public Result updateTime(String code) {
        return new Result<>(code);
    }

    @GetMapping("hasBuyThisGoods/{id}")
    public Result hasBuyThisGoods(@PathVariable String id, Principal principal) {
        return new Result<>(orderService.buyGoods(id, principal));
    }
//    商家
@PostMapping("getAllOrder")
public Result getAllOrder(Integer curr, Integer size, String telephone, OOrder orders){
    String bid = getBid.getbid(telephone);
    System.out.println(bid);
    Page page = new Page(curr,size);
    orders.setBid(bid);
    Page page1 = orderService.getAllOrderBybid(page,bid,orders);
    return new Result(page1);
}
    //    发货
    @PostMapping("sendOrder")
    public Result sendOrder(@RequestParam String code){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("code",code);
        OOrder oOrder = new OOrder();
        oOrder.setSend(1);
        return new Result(orderService.update(oOrder,queryWrapper));
    }
    //    收入统计
    @PostMapping("income")
    public Result income(String telephone){
        String bid = getBid.getbid(telephone);
        List<Map<String,Object>> iNcomeMap = orderService.income(bid);
        return  new Result(iNcomeMap);
    }

}